package com.nbicc.anon.hot.service.impl;

import com.nbicc.anon.hot.service.IAnonHotNewsService;
import com.nbicc.common.RequestPageObj;
import com.nbicc.common.ResponseObj;
import com.nbicc.hot.service.INewsVisitService;
import com.nbicc.news.po.NewsInfo;
import com.nbicc.news.service.INewsInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * @Author: lilingyan
 */
@Service("AnonHotNewsServiceImpl")
public class AnonHotNewsServiceImpl implements IAnonHotNewsService{

    @Resource(name = "NewsVisitServiceImpl")
    private INewsVisitService newsVisitService;
    @Resource(name = "NewsInfoServiceImpl")
    private INewsInfoService newsInfoService;

    @Override
    public ResponseObj find(RequestPageObj<Map<String, Object>> requestPageObj) {
        List<NewsInfo> newsInfos = new ArrayList<>();
        Set visitCountIds = newsVisitService.getVisitCountIds(requestPageObj);
        if(visitCountIds!=null && !visitCountIds.isEmpty()){
            List<NewsInfo> nis = newsInfoService.selectBatchIds(visitCountIds);
            newsInfos.addAll(nis);
        }
//        if(newsInfos.size() < requestPageObj.getPageSize()){
//            requestPageObj.
//                    setPageNum(1).
//                    setPageSize(requestPageObj.getPageSize() - newsInfos.size())
//                    .setSort("createTime desc");
//            Object nis = newsInfoService.find(requestPageObj).getBodyMap().get("result");
//            if(nis != null){
//                newsInfos.addAll((Collection<? extends NewsInfo>) nis);
//            }
//        }
        return ResponseObj.success().setResult(newsInfos);
    }

}
